﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using CarDriver.Resources;
using System.Diagnostics;
using System.Windows.Media;
using System.Windows.Input;
using Microsoft.Xna.Framework.Input.Touch;

namespace CarDriver
{
    public partial class MainPage : PhoneApplicationPage
    {
        car_driver car = new car_driver();
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            TouchPanel.EnabledGestures = GestureType.FreeDrag;
            steering_wheel.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>
                (steering_wheel__ManipulationDelta);
            steering_wheel.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>
                (steering_wheel_ManipulationCompleted);
        }

        private void steering_wheel_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            this.steering_wheel_rotate.Angle = 0;
            car.set_wheel_angle(0);
        }

        void steering_wheel__ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            if (e != null)
            {
                steering_wheel_rotate.Angle += e.DeltaManipulation.Translation.X;
                car.set_wheel_angle(Convert.ToInt32(steering_wheel_rotate.Angle));
              //  msg.set_wheel_angle(int.Parse(steering_wheel_rotate.Angle.ToString())); //fixme: drop int parse.
            }
        }

        private void go_button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void stop_button_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}